<template>
	<view class="add_comm">
	  <form @submit="formSubmit" @reset="">
		<view class="add_comm_title">小区信息</view>
		<view class="ele_title_left bg-white padding-left-sm padding-bottom-xs">
			<view class="ele_title_inner padding-xs">{{info.residential_quarters_name}}</view>
			<view class="ele_address">
				<image class="ele_address_img" src="../../../common/img/dizhi_hui.png" mode=""></image>
				<text>{{info.residential_quarters_address}}</text>
			</view>
		</view>
		<view class="add_comm_title">电费信息</view>
		<view class="add_box">
			<view class="add_inner">
				<view class="add_inner_text">抄见度数</view>
				<input class="add_inner_input" type="text" name="reading_degree" value="" placeholder="请输入抄见度数" />
			</view>
			<view class="add_inner">
				<view class="add_inner_text">本期度数</view>
				<input class="add_inner_input" type="text" name="degree_of_use" value="" placeholder="请输入本期度数" />
			</view>
			<view class="add_inner">
				<view class="add_inner_text">本期电费</view>
				<input class="add_inner_input" type="text" name="electricity_fees" value="" placeholder="请输入本期电费" />
			</view>
		</view>
		<button type="button" class="add_text_btn" form-type="submit">保存</button>
	  </form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				info:'',
				guid:'',
			}
		},
		onLoad(options) {
			let info=JSON.parse(options.item);
			this.info=info;
			this.guid=info.residential_quarters_guid;
		},
		methods: {
			formSubmit: function(e) {
				let formData = e.detail.value;
			    let reading_degree=formData['reading_degree'];
				if(reading_degree.trim()=='' || reading_degree.trim()==null){
					uni.showToast({
						icon: 'none',
					    title: '抄见度数不能为空'
					});
					return;
				}
				let degree_of_use=formData['degree_of_use']
				if(degree_of_use.trim()=='' || degree_of_use.trim()==null){
					uni.showToast({
						icon: 'none',
					    title: '本期度数不能为空'
					});
					return;
				}
				let electricity_fees=formData['electricity_fees']
				if(electricity_fees.trim()=='' || electricity_fees.trim()==null){
					uni.showToast({
						icon: 'none',
					    title: '本期电费不能为空'
					});
					return;
				}
				let that=this;
				that.http.tokenreq({
					url: 'electricitychargeentry/v1/add',
					data:{
						"residential_quarters_guid":that.guid,
						"reading_degree":reading_degree,
						"degree_of_use":degree_of_use,
						"electricity_fees":electricity_fees,
					}
				}).then((res) => {
					console.log("res="+JSON.stringify(res));
					let e=res.data;
					if(e.code==0 && e.success){
						uni.showModal({
							content: e.message,
							showCancel:false,
							success: function (res) {
								if (res.confirm) {
									uni.redirectTo({
										url:'/pages/electricity/electricity/electricity?item='+JSON.stringify(that.info)
									})
								}
							}
						});
					}else{
						uni.showToast({
							icon: 'none',
						    title: e.message
						});
					}
				})
			}
		}
	}
</script>

<style>

</style>
